<?php
class types{

	function checkDate($val){

		if (strtoupper($val)==""){
			return "NOW()";
		}else{
			return $val;
		}
	}
}

class dummy extends types {

	var $table;
	var $cols;
	var $atts;
	var $phpVars;
	var $results;

	function insert(){

		$sqlCols=$sqlVals="";
		foreach ($this->atts as $key=>$val){
			$sqlCols .= " $key,";
			$sqlVals .= " $val,";
		}
		$sqlCols=rtrim($sqlCols,",");
		$sqlVals=rtrim($sqlVals,",");
		$sql = "";
		$sql .= "INSERT INTO $this->table($sqlCols";
		$sql .= ") VALUES (";
		$sql .= "$sqlVals";
		$sql .= ")";

		return $sql;
	}

	function resetAtts(){
		$this->atts=array();
	}
	function setAtts($arr){
		$this->resetAtts();
		$this->atts = $arr;
	}
	function loadItem($id){
		$results=array(
		array("id_table"=>"number4","data"=>"date","sex"=>"char","email"=>"varchar"),
		array("id_table"=>"number3","data"=>"date","sex"=>"char","email"=>"varchar"),
		array("id_table"=>"number2","data"=>"date","sex"=>"char","email"=>"varchar"),
		array("id_table"=>"number1","data"=>"date","sex"=>"char","email"=>"varchar")
		);
		// later we sub in the results with a select?
		return $results[$id];
	}
}


class thing extends dummy {

	function thing(){

		$this->table="tbl_table";
		$this->cols = array(
							"id_table"=>"number",
							"data"=>"date",
							"sex"=>"char",
							"email"=>"varchar"
						);
	}

	function save(){
		$this->setAtts(array("id_table"=>"'1'",
					"data"=>'NOW()',
					"sex"=>"'M'",
					"email"=>"'greg@doutromundo.com'"));

		echo $this->insert();
	}

	function fetch($r){

		return $this->loadItem($r);

	}
}

$f = new thing();
$ar= $f->fetch(1);
echo $ar["id_table"];
?>